﻿using System;
using System.Linq;
using FluentValidation;

namespace NiuX.Common.Tests;

/// <summary>
/// VaildatorHelper
/// </summary>
public class VaildatorHelper
{
    public static string Validate<T>(T source, AbstractValidator<T> sourceValidator) where T : class
    {
        var results = sourceValidator.Validate(source);
        if (!results.IsValid)
            return string.Join(Environment.NewLine, results.Errors.Select(x => x.ErrorMessage).ToArray());
        else
            return "";

    }
}